package com.dragon.app.controller.auth;

import com.dragon.app.config.annotation.Log;
import com.dragon.app.config.annotation.Login;
import com.dragon.common.constant.PlatformConstant;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.auth.AdminService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("auth")
@Api(tags = "登录管理")
public class LoginController {

    @Autowired
    AdminService service;

    @PostMapping("login")
    @ApiOperation(value = "用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", type = "string", required = false, value = "账号"),
            @ApiImplicitParam(name = "password", type = "string", required = true, value = "密码"),
            @ApiImplicitParam(name = "phone", type = "string", required = false, value = "手机号"),
            @ApiImplicitParam(name = "remember", type = "boolean", required = true, value = "记住我")
    })
    @Log
    public ResponseData login(@RequestParam(required = false) String account,
                              @RequestParam(required = false) String phone,
                              @RequestParam String password,
                              @RequestParam Boolean remember) {
        String token = service.login(account, phone, password, remember, PlatformConstant.APP);
        return ResponseData.success(token);
    }


    @GetMapping("logout")
    @ApiOperation(value = "用户登出")
    @Log
    public ResponseData logout(@ApiParam(hidden = true) @Login Integer adminId) {
        service.logout(adminId,PlatformConstant.WEB);
        return ResponseData.success(true);
    }

}
